package com.example.java250729_springboot.controller;

import com.example.java250729_springboot.entity.MessageInfo;
import com.example.java250729_springboot.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageController {
    @Autowired
    private MessageService messageService;
    // private List<MessageInfo> messageInfoList = new ArrayList<>();
    @RequestMapping("/publish")
    public Boolean publish(@RequestBody MessageInfo messageInfo){
        //1.参数校验      2.存储信息
        if (!StringUtils.hasLength(messageInfo.getFrom())
                || !StringUtils.hasLength(messageInfo.getTo())
                || !StringUtils.hasLength(messageInfo.getMessage())){
            System.out.println("参数不规范");
            return false;
        }
        Integer result =  messageService.insertMessage(messageInfo);
        return result == 1;
    }

    @RequestMapping("/getList")
    public List<MessageInfo> getList(){
        return messageService.getList();
    }
}






































